package com.example.skipad

import android.accessibilityservice.AccessibilityService
import android.accessibilityservice.AccessibilityServiceInfo
import android.view.accessibility.AccessibilityEvent


//
// Created by Kong on 2021/9/3.
//
class SkipService : AccessibilityService() {


    override fun onServiceConnected() {
        super.onServiceConnected()
        val config = AccessibilityServiceInfo()
        //配置监听的事件类型为界面变化|点击事件
        config.eventTypes =
            AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED or AccessibilityEvent.TYPE_VIEW_CLICKED
        config.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC
        config.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
        serviceInfo = config
    }

    override fun onAccessibilityEvent(event: AccessibilityEvent) {
        val nodeInfo = event.source ?: return //当前界面的可访问节点信息
        SkipUtil.action(applicationContext, nodeInfo)


        //是启动页面才过滤
//        val launcherActStr = Util.openApp(applicationContext, packageName)
//        val currentActStr = Util.getCurrentActStr(applicationContext, event)
//        if (currentActStr != null && launcherActStr != null) {
//            if (launcherActStr != currentActStr) {
//                Log.d("WindowChange", "onAccessibilityEvent: 不是启动页过滤")
//                return
//            }
//        }

    }


    override fun onInterrupt() {}


}